$(document).ready(function() {
    $("#name").autocomplete({
                    source: function(request, response) {
                            $.ajax({
                                    url: "/client/client_josn",
                                    dataType: "json",
                                    data: {
                    query: request.term
                                    },
                                    success: function(data) {
                                            response($.map(data, function(item) {
                                                return {
                            label: item.name + "   " + item.recommended,
                            value: item.name,
                            recommended: item.recommended
                                                }
                                            }));
                                    }
                            });
                    },
        select: function(e, ui) {
            $("#recommended").val(ui.item.recommended);
        },
                    minLength: 1
     	});

    $("input").keypress(function(e) {
        var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
        if (keyCode == 13) {
            var i;
            for (i = 0; i < this.form.elements.length; i++) {
                if (this == this.form.elements[i])
                    break;
            }
            i = (i + 1) % this.form.elements.length;
            this.form.elements[i].focus();
            return false;
        } else {
            return true;
        }
    });

    $("select").keypress(function(e) {
        var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
        if (keyCode == 13) {
            var i;
            for (i = 0; i < this.form.elements.length; i++) {
                if (this == this.form.elements[i])
                    break;
            }
            i = (i + 1) % this.form.elements.length;
            this.form.elements[i].focus();
            return false;
        } else {
            return true;
        }
    });

});